//Page Object
import { getSetting, openSetting, chooseAddress, showModal, showToast } from "../../utils/asyncWx.js";

Page({
    data: {
        address: {},
        cart: [],

    },
    //options(Object)
    onLoad: function (options) { },
    onReady: function () { },
    onShow: function () {
        const address = wx.getStorageSync("address");
        let cart = wx.getStorageSync("cart") || [];

        cart = cart.filter(v => v.checked)

        let totalPrice = 0;
        let totalNum = 0;
        cart.forEach(v => {
            totalPrice += v.num * v.goods_price;
            totalNum += v.num;
        });
        this.setData({
            address,
            cart,
            totalPrice,
            totalNum
        });
    },
    onHide: function () { },



    //购物车结算
    async handlePay() {
        // const token = wx.getStorageSync('token')
        // if (!token) {
        //     wx.navigateTo({
        //         url: '/pages/auth/auth'
        //     })
        //     return
        // }
        // console.log('已存在token');
        wx.requestPayment({
            timeStamp: '',
            nonceStr: '',
            package: '',
            signType: 'MD5',
            paySign: '',
            success(res) { },
            fail(res) { }
        })
    },
});
